<template>
	<view>
		<view class="">
			<view class="pp20 fj" style="color: #848484; font-size: 28rpx">
				<view v-for="(i, index) in tag_list" :key="index" :class="{ sele: index == sele }"
					@click="choose(i.id)">
					{{ i.title }}({{ i.count }})
				</view>
			</view>
			<view class="line"> </view>
		</view>
		<view class="">
			<view class="" style="border-bottom: 1px solid #f0f0f0; padding-bottom: 30rpx"
				v-for="(val, i) in messageList" :key="i">
				<view class="fa pp10" @click="goChat(val)">
					<u-avatar :src="val.avatar"></u-avatar>
					<view class="" style="padding-left: 15px">
						<view class="f15 fa" style="color: #a2a2a2">
							<view class="f1">
								<text style="color: #161616" class="mr20">{{ val.name || '默认名称' }}</text>
								<text class="mr20"> {{ setStatus(val.gender) || '保密' }}</text>
								<!-- <text>{{ val.age }}岁</text> -->
							</view>
							<view class="f12">
								{{ val.createTime }}
							</view>
						</view>
						<view class="f13 ca2 mt5 text-ellipsis" style="width: 300px">
							{{ val.content || val.diseaseDescription }}
						</view>
					</view>
				</view>
				<!--  -->
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				img: "",
				sele: 0,
				tag_list: [{
						title: "全部",
						count: 0,
						id: "-1",
					},
					{
						title: "待接诊",
						count: 0,
						id: "0",
					},
					{
						title: "接诊中",
						count: 0,
						id: "1",
					},
					{
						title: "已完成",
						count: 0,
						id: "3",
					},
				],
				// patient: uni.getStorageSync('patient')
				patient: [],
				messageList: [],
				options1: [{
					text: "删除",
					style: {
						backgroundColor: "#f56c6c",
					},
				}, ],
			};
		},
		onShow() {
			this.chatList();
			this.count();
		},
		onLoad() {

		},
		methods: {
			goChat(val) {
				console.log(val,"val.appStatus");
				/* 0 待接诊 1接诊中  3已完成 */
				let status = val.appStatus
				
				/* 保存订单id */
				uni.setStorageSync('orderNo',val.orderNo)

				if (status == '0') {
					uni.showToast({
						title: '请接受诊断，再操作',
						duration:1000
					})
					setTimeout(() => {
						this.$pub.go('/pages/jiezhen/jiezhen')
					},2000)
				} else {
					this.$pub.go(
						`/pages/online/online?data=${encodeURIComponent(
					    JSON.stringify(val)
					  )}`
					)
				}

			},


			deleteItem(e) {
				console.log(e, "e");
				let index = e.index;
				this.messageList.splice(index, 1);
				console.log(this.messageList, "me");
			},
			setStatus(status) {
				let obj = {
					1: "男",
					2: "女",
				};
				return obj[status];
			},
			choose(index) {
				this.sele = index + 1;
				if (index == -1) {
					this.chatList();
				} else {
					this.chatList(`${index}`);
				}
			},
			/* 聊天列表 */
			async chatList(status) {
				let re = await this.$API.messageApi.chatList(status);
				/*  */
				if (re) {
					this.messageList = re;
					if (status === undefined) {
						this.tag_list[0].count = this.messageList.length;
					}
				} else {
					console.log("数据为空");
				}
			},
			/* 数量 */
			async count() {
				console.log(1);
				let uemployeeId = uni.getStorageSync("userInfo").userInfo.uemployeeid;
				let re = await this.$API.messageApi.listByDoctorCount(uemployeeId);
				for (var i = 0; i < re.length; i++) {
					console.log(re[i], "1");
					for (var j = 0; j < this.tag_list.length; j++) {
						if (re[i].appStatus == this.tag_list[j].id) {
							this.tag_list[j].count = re[i].count;
						}
					}
				}
			},
		},
	};
</script>

<style>
	.sele {
		color: #2d81ff;
	}
</style>